import { defineStore } from 'pinia';
import type { NotificationItem } from '@/types/interface';

// @ts-nocheck
interface LogsType {
  id: number;
  userName: string;
  refType: number;
  refId: number;
  refName: string;
}
interface MembersType {
  isOneself: Boolean;
  phone: string;
  company: string;
  email: string;
  auditStatus: number;
  name: string;
}
interface UnitType {
  id: number;
  level?: number;
  number?: number;
  parentId?: number;
  remarks?: string;
  sort?: number;
  text: string;
  type?: number;
  value?: string;
}
interface projectData {
  coverUrl: string;
  createDate: string;
  isAsterisk: Boolean;
  name: string;
  description: string;
  createUserName: string;
  projectId: number | string;
  publishStatus: number;
  role: number;
  logs: Array<LogsType>;
  members: Array<MembersType>;
}
interface StyleInfo {
  background: string;
}
export const useProjectStore = defineStore('project', {
  state: () => ({
    id: 0,
    delId: 0,
    moduleList: {
      projectId: 0,
      parentId: 0,
      sort: [],
    },
    heartbeatCurrent: 0, //页面心跳值
    modelIndex: false, //辅助信息弹框层级
    auxiliaryId: 0, //辅助信息id
    auxiliaryvisible: false, //辅助信息弹框
    auxiliaryType: false, //更新状态
    template9ScrollType: false,
    template9MenuShow: true, //模版9置顶按钮显示
    AddUnitstatus: false,
    planChildType: false,
    tabvalue: 1,
    uploadModel: false,
    drawerShow: false,
    visitExhibitsInfoShow: false,
    descriptionExhibitsInfoShow: false,
    textInfoShow: false,
    templateUnitType: false, //书画模板首页控制
    templateType: 0,
    correlationModuleId: 0,
    exhibitsDescription: '',
    exhibitsName: '',
    scrollBox: 0,
    isUnitTem6: -1,
    isCollectBtn: true,
    isBack: false,
    getUnitSlectInfo: {
      id: 0,
      level: 0,
      number: 0,
      parentId: 0,
      remarks: '',
      sort: 0,
      text: '',
      type: 1,
      value: '',
    },
    glanceOver: false,
    linkType: false,
    childModel: {
      id: 0,
      level: 0,
      number: 0,
      parentId: 0,
      remarks: '',
      sort: 0,
      text: '',
      type: 1,
      value: '',
      auxiliaryTotal: 0,
      children: [],
    },
    parentId: 0,
    projectRole: 3,
    styleInfo: {
      logo: '',
      moduleList: [],
      id: 0, //模板id
      projectId: 0, //模板id
      themeColor: '#CFBDA8', //主题色
      auxiliaryColor: '#F0E9E1', //辅助色
      background: '#FAF9F7', //背景色
      shmentColor: '#D2AD77', //点缀色
      fontColor: '#333', //字体色
      colorType: 1, //颜色id
      fontFamily: 'SourceHanSerifCN', //标题字体
      textFamily: 'SourceHanSerifCN', //正文字体
      sizeType: 1, //字体类型
      contentSize: '19px', //正文字号
      titleSize: '34px', //标题字号
      mintitleSize: '20px', //小标题字号
      styleType: 1, //风格样式
      banners: [], //首页轮播图
      wapBanners: [], //移动端轮播图
    },
    projectInfo: {
      coverUrl: '371947843936325',
      createDate: '2023/02/01 09:24:22',
      createUserName: '',
      description: '',
      isAsterisk: true,
      logs: [],
      members: [],
      name: '恋山游',
      projectId: 0,
      publishStatus: 1,
      role: 3,
    },
    correlationExhibits: [],
    BiographyMenuType: -1,
    research7Type: false,
    template5Type: false,
    template9ExhibitsShow: false, //模版9展品图库弹框状态
    tmplate2ChildShow: {
      id: 0,
      level: 0,
      number: 0,
      parentId: 0,
      remarks: '',
      sort: 0,
      text: '',
      type: 1,
      value: '',
      children: [],
    },
    current: 0, //模板一定位二级单元
    Template6MenuType: -1,
    Template6MenuCurrent: 0,
    wapBiographyMenuType: -1, //模板六移动端
    stsyCurrent: 0, //模板14记录第一级单元
  }),
  getters: {},
  actions: {
    setHeartbeatCurrent(e?: boolean) {
      this.heartbeatCurrent = this.heartbeatCurrent + 1;
      if (e) {
        this.heartbeatCurrent = 0;
      }
    },
    settemplate9MenuShow(e: boolean) {
      this.template9MenuShow = e;
    },
    settemplate9ExhibitsShow(e: boolean) {
      this.template9ExhibitsShow = e;
    },
    setModelIndex(e: boolean) {
      this.modelIndex = e;
    },
    setAuxiliaryvisible(e: boolean) {
      this.auxiliaryvisible = e;
    },
    setAuxiliaryId(e: number) {
      this.auxiliaryId = e;
    },
    setAuxiliaryType() {
      this.auxiliaryType = !this.auxiliaryType;
    },
    settemplate9ScrollType(e: boolean) {
      this.template9ScrollType = e;
    },
    settmplate2ChildShow(e?: any) {
      if (e) {
        this.tmplate2ChildShow = e;
      } else {
        this.tmplate2ChildShow = {
          id: 0,
          level: 0,
          number: 0,
          parentId: 0,
          remarks: '',
          sort: 0,
          text: '',
          type: 1,
          value: '',
          children: [],
        };
      }
    },
    settemplate5Type() {
      this.template5Type = !this.template5Type;
    },
    setresearch7Type(e: boolean) {
      this.research7Type = e;
    },
    setBiographyMenuType(e: number) {
      this.BiographyMenuType = e;
    },
    setIsUnitTem6(data) {
      this.isUnitTem6 = data;
    },
    setScrollBox(data: number) {
      this.scrollBox = data;
    },
    setCorrelationModuleId(data: number | string) {
      this.correlationModuleId = data;
    },
    setGetUnitSlectInfo(data?: UnitType) {
      if (data) {
        this.getUnitSlectInfo = data;
      } else {
        this.getUnitSlectInfo = {
          id: 0,
          level: 0,
          number: 0,
          parentId: 0,
          remarks: '',
          sort: 0,
          text: '',
          type: 1,
          value: '',
        };
      }
    },
    settextInfoShow(data: boolean) {
      this.textInfoShow = data;
    },
    setvisitExhibitsInfoShow(data: boolean) {
      this.visitExhibitsInfoShow = data;
    },
    setDescriptionExhibitsInfoShow(data: boolean) {
      this.descriptionExhibitsInfoShow = data;
    },
    setUploadModel() {
      this.uploadModel = !this.uploadModel;
    },
    setdrawerShow(data: boolean) {
      this.drawerShow = data;
    },
    setLinkType(data: boolean) {
      this.linkType = data;
    },
    setTeplateType(data: number) {
      this.templateType = data;
    },
    settemplateUnitType(e: boolean) {
      this.templateUnitType = e;
    },
    setstyleInfo(data: any) {
      this.styleInfo.logo = data.logo;
      this.styleInfo.moduleList = data.moduleList;
      this.styleInfo.id = data.id;
      this.styleInfo.projectId = data.projectId;
      this.styleInfo.themeColor = data.themeColor ? data.themeColor : '#CFBDA8';
      this.styleInfo.auxiliaryColor = data.auxiliaryColor ? data.auxiliaryColor : '#F0E9E1';
      this.styleInfo.background = data.background ? data.background : '#FAF9F7';
      this.styleInfo.shmentColor = data.shmentColor ? data.shmentColor : '#D2AD77';
      this.styleInfo.fontColor = data.fontColor ? data.fontColor : '#333';
      this.styleInfo.fontFamily = data.fontFamily ? data.fontFamily : 'SourceHanSerifCN';
      this.styleInfo.textFamily = data.textFamily ? data.textFamily : 'SourceHanSerifCN';
      this.styleInfo.sizeType = data.sizeType ? data.sizeType : 1;
      this.styleInfo.contentSize = '16px';
      this.styleInfo.titleSize = '34px';
      this.styleInfo.mintitleSize = '20px';
      this.styleInfo.styleType = data.styleType ? data.styleType : 1;
      this.styleInfo.wapBanners = data.wapBanners;
      if (data.banners) {
        this.styleInfo.banners = [];
        data.banners.forEach((element) => {
          if (element.url) {
            this.styleInfo.banners.push(element);
          }
        });
      } else {
        this.styleInfo.banners = [];
      }
      // this.styleInfo.banners = data.banners ? data.banners : [];
      this.styleInfo.colorType = data.colorType ? data.colorType : 1;
      console.log('moduleList', this.styleInfo.moduleList);
    },
    setstyleInfoModel(data) {
      this.styleInfo.moduleList = data;
    },
    setColorType(data: number) {
      this.styleInfo.colorType = data;
    },
    setchildModel(styleInfo: any) {
      this.childModel = styleInfo;
    },
    setglanceOver() {
      this.glanceOver = !this.glanceOver;
    },
    setColor(data: any) {
      this.styleInfo.themeColor = data.themeColor;
      this.styleInfo.auxiliaryColor = data.auxiliaryColor;
      this.styleInfo.background = data.background;
      this.styleInfo.shmentColor = data.shmentColor;
      this.styleInfo.fontColor = data.fontColor;
      this.styleInfo.colorType = data.id;
    },
    setFontsize(data: any) {
      this.styleInfo.contentSize = data.contentSize;
      this.styleInfo.titleSize = data.titleSize;
      this.styleInfo.mintitleSize = data.mintitleSize;
    },
    setFontFamily(data: any, type: number) {
      if (type === 1) {
        this.styleInfo.fontFamily = data;
      } else {
        this.styleInfo.textFamily = data;
      }
    },
    setBanner(data: any) {
      this.styleInfo.banners = data;
    },
    setWapBanner(data: any) {
      this.styleInfo.wapBanners = data;
    },
    setLogo(data: any) {
      this.styleInfo.logo = data;
    },
    setStypeType(data: any) {
      this.styleInfo.styleType = data.id;
    },
    setProjectData(data: projectData) {
      this.projectInfo = data;
    },
    setProjectRole(data: number) {
      this.projectRole = data;
    },
    setCurrent(data: number) {
      this.current = data;
    },
    setTemplate6MenuType(e: number) {
      this.Template6MenuType = e;
    },
    setTemplate6MenuCurrent(e: number) {
      this.Template6MenuCurrent = e;
    },
    setwapBiographyMenuType(e: number) {
      this.wapBiographyMenuType = e;
    },
    setStsyCurrent(e: number) {
      this.stsyCurrent = e;
    },
  },
  persist: true,
});
